#include <bits/stdc++.h>

using namespace std;

struct edge
{
    int to;
    int nxt;
};

edge e[500001 << 1];
int tot = 0;
int head[500001];
int LOG[500005];
int depth[500005];
int fa[500005][20];

void add(int x, int y)
{
    tot++;
    e[tot].to = y;
    e[tot].nxt = head[x];
    head[x] = tot;
}

void dfs(int curr, int root)
{
    depth[curr] = depth[root] + 1;
    fa[curr][0] = root;
    for (int i = 1; i <= LOG[depth[curr]]; i++)
    {
        fa[curr][i] = fa[fa[curr][i - 1]][i - 1];
    }

    for (int i = head[curr]; i != 0; i = e[i].nxt)
    {
        if (e[i].to != root)
        {
            dfs(e[i].to, curr);
        }
    }
}

int LCA(int u, int v)
{
    if (depth[u] < depth[v])
    {
        swap(u, v);
    }

    while (depth[u] != depth[v])
    {
        u = fa[u][LOG[depth[u] - depth[v]]];
    }
    if (u == v)
        return u;
    for (int i = LOG[depth[u]]; i >= 0; i--)
    {
        if (fa[u][i] != fa[v][i])
        {
            u = fa[u][i];
            v = fa[v][i];
        }
    }
    return fa[u][0];
}

int main()
{
    int N, M, S;
    cin >> N >> M >> S;
    for (int i = 0; i < N - 1; i++)
    {
        int u, v;
        cin >> u >> v;
        add(u, v);
        add(v, u);
    }
    for (int i = 2; i < 500005; i++)
        LOG[i] = LOG[i >> 1] + 1;

    dfs(S, S);
    while (N--)
    {
        int u, v;
        cin >> u >> v;
        cout << LCA(u, v) << endl;
    }
    return 0;
}